home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Pascal
/
SWar
/
Main.p
< prev
next >
Wrap
Text File
|
1995-06-15
|
5KB
|
238 lines
program SWar;
uses
{$IFC UNDEFINED THINK_PASCAL}
Types, QuickDraw, Events, Menus, Dialogs, Fonts, Resources, Devices, ToolUtils,
{$ENDC}
Globals, Util, Game, Init;
{$IFC DEFINED THINK_PASCAL}
PROCEDURE GetMenuItemText(theMenu: MenuRef; item: INTEGER; VAR itemString: Str255);
INLINE $A946;
{$ENDC}
procedure HandleAppleChoice (theItem: Integer);
var
accName: Str255;
accNumber: Integer;
savePort: GrafPtr;
begin
case (theItem) of
1:
;
otherwise
begin
GetPort(savePort);
GetMenuItemText(gAppleMenu, theItem, accName);
accNumber := OpenDeskAcc(accName);
SetPort(savePort);
end;
end; (* case *)
end; (* HandleAppleChoice() *)
procedure HandleFileChoice (theItem: Integer);
var
savePort: GrafPtr;
begin
case (theItem) of
1:
begin
EnableItem(gFileMenu, 2);
EnableItem(gFileMenu, 5);
gPlaying := TRUE;
gPauseOn := FALSE;
InitGame;
HideCursor;
GetPort(savePort);
SetPort(GrafPtr(gPictureWindow));
ShowWindow(WindowPtr(gPictureWindow));
{}
{ Must set FG and BG pens for CopyBits to work}
{ }
RGBForeColor(myBlack);
RGBBackColor(myWhite);
end;
2:
begin
if (gPauseOn) then
begin
gPauseOn := FALSE;
HideCursor;
end (* if *)
else
begin
gPauseOn := TRUE;
ShowCursor;
end; (* else *)
SetChecks;
end;
3:
begin
gSoundOn := not gSoundOn;
SetChecks;
end;
5:
;
7:
begin
gDone := TRUE;
EnableItem(gFileMenu, theItem);
DisableItem(gFileMenu, 2);
DisableItem(gFileMenu, 5);
end;
end; (* end *)
end; (* HandleFileChoice() *)
procedure HandleMenuChoice (menuChoice: Longint);
var
theMenu: Integer;
theItem: Integer;
begin
if (menuChoice <> 0) then
begin
theMenu := HiWord(menuChoice);
theItem := LoWord(menuChoice);
case (theMenu) of
500:
HandleAppleChoice(theItem);
501:
HandleFileChoice(theItem);
end; (* case *)
HiliteMenu(0);
end; (* if *)
end; (* HandleMenuChoice() *)
procedure HandleMouseDown;
var
whichWindow: WindowPtr;
thePart: Integer;
menuChoice, windSize: LongInt;
begin
thePart := FindWindow(gTheEvent.where, whichWindow);
case (thePart) of
inMenuBar:
begin
menuChoice := MenuSelect(gTheEvent.where);
HandleMenuChoice(menuChoice);
end;
inSysWindow:
SystemClick(gTheEvent, whichWindow);
inDrag:
;
{ DragWindow(whichWindow, gTheEvent.where, &gDragRect);}
inGoAway:
;
{ gDone = TRUE;}
inContent:
;
inGrow:
;
inZoomIn:
;
inZoomOut:
;
otherwise
end; (* case *)
end; (* HandleMouseDown *)
procedure HandleEvent;
var
theChar: char;
hasEvent: Boolean;
begin
if (not wneAvail) then
begin
hasEvent := GetNextEvent(everyEvent, gTheEvent);
SystemTask;
end (* if *)
else
hasEvent := WaitNextEvent(everyEvent, gTheEvent, 0, nil);
case (gTheEvent.what) of
mouseDown:
if ((gPauseOn and gPlaying) or not gPlaying) then
HandleMouseDown;
keyDown, autoKey:
begin
theChar := Char(BAnd(gTheEvent.message, charCodeMask));
if BAnd(gTheEvent.modifiers, cmdKey) <> 0 then
HandleMenuChoice(MenuKey(theChar));
end;
updateEvt:
;
nullEvent:
;
mouseUp:
;
keyUp:
;
diskEvt:
;
activateEvt:
;
{Removed some events that will never be interesting.}
otherwise
;
end; (* case *)
end; (* HandleEvent() *)
{Procedure main;}
var
tics: Integer;
const
_WaitNextEvent = $A860;
_Unimplemented = $A89F;
_GetCIcon = $AA1E; {E.g. any Color QuickDraw routine}
k32bQD = $AB1D;
begin
MaxApplZone;
ToolBoxInit;
{$IFC UNDEFINED THINK_PASCAL}
GetDateTime(LongInt(qd.randSeed));
{$ELSEC}
GetDateTime(LongInt(randSeed));
{$ENDC}
wneAvail := FALSE;
if noErr <> SysEnvirons(1, theSysEnv) then
;
if theSysEnv.machineType >= 1 then
begin
wneAvail := NGetTrapAddress(_WaitNextEvent, ToolTrap) <> NGetTrapAddress(_Unimplemented, ToolTrap);
gColorQDFlag := NGetTrapAddress(_GetCIcon, ToolTrap) <> NGetTrapAddress(_Unimplemented, ToolTrap);
g32bQDFlag := NGetTrapAddress(k32bQD, ToolTrap) <> NGetTrapAddress(_Unimplemented, ToolTrap);
end; (* if *)
DrawMenuBar;
WindowInit;
gDone := FALSE;
gPlaying := FALSE;
gPauseOn := FALSE;
gSoundOn := TRUE;
gSndIsInitted := FALSE;
SetChecks;
LoadPieces;
LoadSounds;
InitColors;
while (not gDone) do
begin
if (gPlaying and not gPauseOn) then
begin
GameCycle;
end; (* if *)
HandleEvent;
end; (* while *)
ExitAppl;
end. (* main () *)